//###############
// FILE : NOTOperator.java
// WRITER : Lior Zimmerman liorz06 066462300
// WRITER : Ohad Dan ohad_dan 036767960
// EXERCISE : oop ex3 2008
// DESCRIPTION: Representation of the unary logic operator NOT.
//###############
package oop.ex3.fileSearchModel.filters;

import oop.ex3.fileSearchModel.filters.exceptions.*;
import oop.ex3.fileSearchModel.parser.exceptions.ParsingException;
/**
 * Representation of the unary logic operator NOT.
 */
public class NOTOperator extends LogicOperator {
    /**
     * Constructs a new NOT logic operator.
     */
	public NOTOperator(){
    	super();
    }
	/**
	 * Constructs a new NOT logic operator.
	 * @param child1 The one child of the operator. 
	 * Represented as a left child only in a binary tree.
//	 * @param child2 Second child of of the operator -should be null. 
	 * @param status Status of the condition.
	 */
	public NOTOperator( Conditionable child1, Conditionable child2,
			STATUS status) throws ParsingException{
		if ( child1 != null && child2 != null ) {
			throw new ParsingException( "Error:Invalid filter expression");
		}
	}
	/**
	 * Sets operator's left child.
	 * @param op Left child to be set. Because Not is an unary operator
	 * should be null.
	 */
    public void setLeftChild( Conditionable op ) throws ParsingException{
    	if ( op != null ) {
    		throw new ParsingException( "Error:Invalid filter expression");
    	}
    }
    /**
     * Constructs a new NOT operator.
     * @param child operand of Not operator.
     * @param status Status of the operator codition.
     */
    public NOTOperator( Conditionable child, STATUS status) {
    	super(null, child, status);
    }
	/**
	 * Return the value of the condition.
	 * @return Condition's status - True,False,Unlnown.
	 */
	public STATUS getCondition() throws FilterDataException{
        if ( _rightTerm.getCondition() == STATUS.TRUE ) {
        	return STATUS.FALSE;
        }else if ( _rightTerm.getCondition() == STATUS.FALSE ) {
        	return STATUS.TRUE;
        }
        /*NOT will never have a left child , therefore, there is no need to
        check it .. (left child will be null.*/
        return STATUS.UNKNOWN;

    }
	/**
	 *  Clones the object - return a new object with same properties.
	 */
	public LogicOperator clone() {
		return new NOTOperator( _rightTerm, _status );
	}
}
